home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DKBSRC.ARJ / COLOUR.C < prev    next >
C/C++ Source or Header  |  1991-05-04  |  4KB  |  111 lines

  1. /*****************************************************************************
  2. *
  3. *                                   colour.c
  4. *
  5. *   from DKBTrace (c) 1990  David Buck
  6. *
  7. *  This module implements routines to manipulate colours.
  8. *
  9. * This software is freely distributable. The source and/or object code may be
  10. * copied or uploaded to communications services so long as this notice remains
  11. * at the top of each file.  If any changes are made to the program, you must
  12. * clearly indicate in the documentation and in the programs startup message
  13. * who it was who made the changes. The documentation should also describe what
  14. * those changes were. This software may not be included in whole or in
  15. * part into any commercial package without the express written consent of the
  16. * author.  It may, however, be included in other public domain or freely
  17. * distributed software so long as the proper credit for the software is given.
  18. *
  19. * This software is provided as is without any guarantees or warranty. Although
  20. * the author has attempted to find and correct any bugs in the software, he
  21. * is not responsible for any damage caused by the use of the software.  The
  22. * author is under no obligation to provide service, corrections, or upgrades
  23. * to this package.
  24. *
  25. * Despite all the legal stuff above, if you do find bugs, I would like to hear
  26. * about them.  Also, if you have any comments or questions, you may contact me
  27. * at the following address:
  28. *
  29. *     David Buck
  30. *     22C Sonnet Cres.
  31. *     Nepean Ontario
  32. *     Canada, K2H 8W7
  33. *
  34. *  I can also be reached on the following bulleton boards:
  35. *
  36. *     OMX              (613) 731-3419
  37. *     Mystic           (613) 596-4249  or  (613) 596-4772
  38. *
  39. *  Fidonet:   1:163/109.9
  40. *  Internet:  dbuck@ccs.carleton.ca
  41. *  The "You Can Call Me RAY" BBS    (708) 358-5611
  42. *
  43. *  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  44. *
  45. *     The "You Can Call Me RAY" BBS (708) 358-5611
  46. *     The Information Exchange BBS  (708) 945-5575
  47. *
  48. *****************************************************************************/
  49.  
  50.  
  51. #include "frame.h"
  52. #include "vector.h"
  53. #include "dkbproto.h"
  54.  
  55. #define FABS(x) ((x) < 0.0 ? (0.0 - (x)) : (x))
  56.  
  57. DBL Colour_Distance (colour1, colour2)
  58.    COLOUR *colour1, *colour2;
  59.    {
  60.    return (FABS (colour1->Red - colour2->Red)
  61.          + FABS (colour1->Green - colour2->Green)
  62.          + FABS (colour1->Blue - colour2->Blue));
  63.    }
  64.  
  65. void Add_Colour (result, colour1, colour2)
  66.    COLOUR *result, *colour1, *colour2;
  67.    {
  68.    result->Red = colour1->Red + colour2->Red;
  69.    result->Green = colour1->Green + colour2->Green;
  70.    result->Blue = colour1->Blue + colour2->Blue;
  71.    result->Alpha = colour1->Alpha + colour2->Alpha;
  72.    }
  73.  
  74. void Scale_Colour (result, colour, factor)
  75.    COLOUR *result, *colour;
  76.    DBL factor;
  77.    {
  78.    result->Red = colour->Red * factor;
  79.    result->Green = colour->Green * factor;
  80.    result->Blue = colour->Blue * factor;
  81.    result->Alpha = colour->Alpha * factor;
  82.    }
  83.  
  84. void Clip_Colour (result, colour)
  85.    COLOUR *result, *colour;
  86.    {
  87.    if (colour -> Red > 1.0)
  88.       result -> Red = 1.0;
  89.    else if (colour -> Red < 0.0)
  90.       result -> Red = 0.0;
  91.    else result -> Red = colour -> Red;
  92.  
  93.    if (colour -> Green > 1.0)
  94.       result -> Green = 1.0;
  95.    else if (colour -> Green < 0.0)
  96.       result -> Green = 0.0;
  97.    else result -> Green = colour -> Green;
  98.  
  99.    if (colour -> Blue > 1.0)
  100.       result -> Blue = 1.0;
  101.    else if (colour -> Blue < 0.0)
  102.       result -> Blue = 0.0;
  103.    else result -> Blue = colour -> Blue;
  104.  
  105.    if (colour -> Alpha > 1.0)
  106.       result -> Alpha = 1.0;
  107.    else if (colour -> Alpha < 0.0)
  108.       result -> Alpha = 0.0;
  109.    else result -> Alpha = colour -> Alpha;
  110.    }
  111.